package com.ww.springboot.boot.thread.study.executor;

import io.netty.util.concurrent.DefaultThreadFactory;
import lombok.SneakyThrows;

import java.util.concurrent.*;

/**
 * 测试当队列 线程池都满了之后的默认处理逻辑是什么
 *
 * 测试结果为直接报错
 *
 * @author wanwei
 * @since 2021-04-20 11:03
 */
public class ExecutorDemo2 {
    private static ExecutorService executorService = new ThreadPoolExecutor(8, 8,
            1, TimeUnit.SECONDS, new ArrayBlockingQueue(10),new DefaultThreadFactory("测试"));

    public static void main(String[] args) throws InterruptedException {

        for (int i = 0; i < 100; i++) {
            executorService.execute(new ThreadDemo());
        }
        executorService.shutdown();
        while (!executorService.isTerminated()) {
            TimeUnit.SECONDS.sleep(1);
        }
    }

    static class ThreadDemo implements Runnable {

        @SneakyThrows
        @Override
        public void run() {
            System.out.println(Thread.currentThread());
            TimeUnit.SECONDS.sleep(10);
        }
    }
}
